#include "myprofile.h"
#include <QDateTime>
#include <QTextEdit>
MyProfile::MyProfile(QTextEdit *te) : _te(te) {}

void MyProfile::clear() { _te->clear(); }

void MyProfile::append(ProfileType type, const QString &info,
                       const QString &str) {
  QString current_date = QDateTime::currentDateTime().toString("hh:mm:ss");
  switch (type) {
  case ProfileType::TRACE:
    this->_te->append(
        QString("<div style='color:#ffffff'><b>[%1]::信息:</b>%2>>%3</div>")
            .arg(current_date)
            .arg(info)
            .arg(str));
    break;
  case ProfileType::UP:
    this->_te->append(
        QString("<div style='color:#77d334'><b>[%1]::上行:</b>%2>>%3</div>")
            .arg(current_date)
            .arg(info)
            .arg(str));
    break;
  case ProfileType::DOWN:
    this->_te->append(
        QString("<div style='color:#d37734'><b>[%1]::下行:</b>%2>>%3</div>")
            .arg(current_date)
            .arg(info)
            .arg(str));
    break;
  case ProfileType::WARNING:
    this->_te->append(
        QString("<div style='color:#ffff00'><b>[%1]::警告:</b>%2>>%3</div>")
            .arg(current_date)
            .arg(info)
            .arg(str));
    break;
  case ProfileType::ERROR:
    this->_te->append(
        QString("<div style='color:#ff2222'><b>[%1]::错误:</b>%2>>%3</div>")
            .arg(current_date)
            .arg(info)
            .arg(str));
    break;
  }
}

void MyProfile::save(const QString &fileName) {
  // TODO
}
